﻿<?php
/**
 * 添加题目功能
 *
 * @author kinet <380511703@qq.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */

session_start();
require_once( 'path.php' );
require_once( SOJ_ROOT.'/include/function/lib.php');


$tpl = new my_smarty();

//若未登录,则重定向到登录界面
if( empty($_SESSION['admin']) ){

	$_SESSION['success_message'] = 'do not login yet , '.$_SESSION['admin'];
	header( 'Location:../manager/manager_login.php' );
	exit ;
}
//处理由其他页面保存在会话中的错误信息
if( !empty($_SESSION['errors']) ){

	$tpl->assign( 'errors' , $_SESSION['errors']  );
	//清除之前的错误信息
	unset( $_SESSION['errors'] );
}
$request=$_POST;
if(empty($request['problem_no'])||empty($request['title'])||empty($request['content'])||empty($request['input'])||empty($request['output'])
   ||empty($request['sample_input'])||empty($request['sample_output'])||empty($request['time_limit'])
   ||empty($request['mem_limit'])||empty($request['tip'])){
   	header( 'Location:../manager/manager_problem.php' );
}

$tpl->assign('admin', $_SESSION['admin']);
try{
 $db=  db_connect();
 $problem=new problem_process($db);
 $problem->load('problem_no',$request['problem_no']);
 $problem->set('title',$request['title']);
 $problem->set('content',$request['content']);
 $problem->set('input',$request['input']);
 $problem->set('output',$request['output']);
 $problem->set('sample_input',$request['sample_input']);
 $problem->set('sample_output',$request['sample_output']);
 $problem->set('time_limit',$request['time_limit']);
 $problem->set('mem_limit',$request['mem_limit']);
 $problem->set('tip',$request['tip']);
 $problem->save();
 $problem_test_right=new problem_test_right_process($db);
 try{
 $problem_test_right->load('problem_no',$request['problem_no']);
 }
 catch(Exception $e){
 }
 $problem_test_right->set('problem_no',$request['problem_no']);
 $problem_test_right->set('test0',$request['test0']);
 $problem_test_right->set('test1',$request['test1']);
 $problem_test_right->set('test2',$request['test2']);
 $problem_test_right->set('test3',$request['test3']);
 $problem_test_right->set('test4',$request['test4']);
 $problem_test_right->set('test5',$request['test5']);
 $problem_test_right->set('test6',$request['test6']);
 $problem_test_right->set('test7',$request['test7']);
 $problem_test_right->set('test8',$request['test8']);
 $problem_test_right->set('test9',$request['test9']);
 $problem_test_right->set('right0',$request['right0']);
 $problem_test_right->set('right1',$request['right1']);
 $problem_test_right->set('right2',$request['right2']);
 $problem_test_right->set('right3',$request['right3']);
 $problem_test_right->set('right4',$request['right4']);
 $problem_test_right->set('right5',$request['right5']);
 $problem_test_right->set('right6',$request['right6']);
 $problem_test_right->set('right7',$request['right7']);
 $problem_test_right->set('right8',$request['right8']);
 $problem_test_right->set('right9',$request['right9']);
 $problem_test_right->save();
header( 'Location:../manager/manager_problem_detail.php?no='.$request['problem_no']);
}
catch(Exception $e){
	 $_SESSION['errors']="添加失败请注意格式";
	 header( 'Location:../manager/manager_problem_add.php');
}


